home *** CD-ROM | disk | FTP | other *** search
/ Aminet 52 / Aminet 52 (2002)(GTI - Schatztruhe)[!][Dec 2002].iso / Aminet / dev / gg / gengetopt-2.6.lha / gengetopt-2.6 / doc / main1.cc < prev    next >
C/C++ Source or Header  |  2002-03-02  |  1KB  |  52 lines

  1. /* main1.cc */
  2. /* we try to use gengetopt generated file in a C++ program */
  3. /* we don't use autoconf and automake vars */
  4.  
  5. #include <iostream.h>
  6. #include "stdlib.h"
  7.  
  8. #include "cmdline1.h"
  9.  
  10. int
  11. main (int argc, char **argv)
  12. {
  13.   gengetopt_args_info args_info;
  14.  
  15.   cout << "This one is from a C++ program" << endl ;
  16.   cout << "Try to launch me with some options" << endl ;
  17.   cout << "(type sample1 --help for the complete list)" << endl ;
  18.   cout << "For example: ./sample1 *.* --funct-opt" << endl ;
  19.  
  20.   /* let's call our cmdline parser */
  21.   if (cmdline_parser (argc, argv, &args_info) != 0)
  22.     exit(1) ;
  23.  
  24.   cout << "Here are the options you passed..." << endl;
  25.  
  26.   for ( unsigned i = 0 ; i < args_info.inputs_num ; ++i )
  27.     cout << "file: " << args_info.inputs[i] << endl ;
  28.  
  29.   if ( args_info.funct_opt_given )
  30.     cout << "You chose --funct-opt or -F." << endl ;
  31.  
  32.   if ( args_info.str_opt_given )
  33.     cout << "You inserted " << args_info.str_opt_arg << " for " <<
  34.       "--str-opt option." << endl ;
  35.  
  36.   if ( args_info.int_opt_given )
  37.     cout << "This is the integer you input: " << 
  38.       args_info.int_opt_arg << "." << endl;
  39.  
  40.   if (args_info.flag_opt_given)
  41.     cout << "The flag option was given!" << endl;
  42.  
  43.   cout << "The flag is " << ( args_info.flag_opt_flag ? "on" : "off" ) <<
  44.     "." << endl ;
  45.  
  46.   cout << args_info.def_opt_arg << "! ";
  47.  
  48.   cout << "Have a nice day! :-)" << endl ;
  49.  
  50.   return 0;
  51. }
  52.